package cn.tedu.basic;

import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import java.util.SortedMap;

//测试日期格式化工具类--SimpleDateFormat
public class Test4_Date {
    public Test4_Date() throws ParseException {
    }

    public static void main(String[] args) throws ParseException {
        Method();
        Method2();
        Method3();
        Method4();

    }
    public static void Method() throws ParseException {
        //创建对象
        SimpleDateFormat sd =new SimpleDateFormat("yyyy-MM-dd");
        //调用方法
       Date d = sd.parse("2008-08-08");
       //好处是:使用date的getXxx();
        System.out.println(d);
        System.out.println(d.getMonth()+1);
        System.out.println(d.getDay());
        System.out.println(d.getYear());
    }
    //出生天数
    public static void Method2() throws ParseException {
        //接收用户输入的出生日期
       String  s=new Scanner(System.in).nextLine();
       SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
        //算天数
       Date da =sdf.parse(s);
       long start =da.getTime();
       long now =System.currentTimeMillis();
       System.out.println((now-start)/1000/60/60/24);
    }
    public static void Method3() throws ParseException {
        SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = s1.parse("2009-08-18");
        System.out.println(d1.getDay());
        System.out.println(d1.getTime());
        System.out.println(d1.getMonth()+1);
        System.out.println(d1.getYear());
    }
    public static void Method4() throws ParseException {
        String sr =new Scanner(System.in).nextLine();
        SimpleDateFormat sdft =new SimpleDateFormat("yyyy-MM-dd");
        Date dt =sdft.parse(sr);
        long start =dt.getTime();
        long now =System.currentTimeMillis();
        System.out.println((now -start)/60/60/24/1000);
    }
}
